<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="btn">排序</button>
<ul id="ul">
    <li>34</li>
    <li>22</li>
    <li>3</li>
    <li>45</li>
    <li>12</li>
</ul>
<script>
    var oUl = document.getElementsByTagName('ul')[0];
    var aLi = document.getElementsByTagName('li');
    var oBtn = document.getElementById('btn');
    oBtn.onclick = function () {
    var arr = [];
    for(var i=0;i<aLi.length;i++){
        arr[i] = aLi[i];
    }
    arr.sort(function (li1,li2) {
        var n1 = parseInt(li1.innerHTML);
        var n2 = parseInt(li2.innerHTML);
        return n1-n2;
    })
    for(var i=0;i<arr.length;i++){
        oUl.appendChild(arr[i]);
    }

    }


</script>


</body>
</html>